<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "log_lut".
 *
 * @property int $log_id
 * @property string $action
 * @property string $response
 * @property string $crt_time
 * @property string $crt_name
 */
class LogLut extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'log_lut';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['action', 'response'], 'required'],
            [['log_id'], 'integer'],
            [['crt_time'], 'safe'],
            [['action', 'crt_name'], 'string', 'max' => 45],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'log_id' => 'Log ID',
            'action' => 'Action',
            'response' => 'Response',
            'crt_time' => 'Crt Time',
            'crt_name' => 'Crt Name',
        ];
    }


    /**
     * @param bool $insert
     *
     * @return bool
     * @author sally
     * @date   2020-06-28
     */
    public function beforeSave($insert)
    {
        if(parent::beforeSave($insert)){

            $this->crt_time = date('y-m-d H:i:s');
            $this->crt_name = Yii::$app->user->identity->username;

            return true;
        }
        else{
            return false;
        }
    }
}
